package ltd.hanamaki.study.generic;

public class GenericDemo01 {


    public static void main(String[] args) {
        Integer arr[] = {1, 2, 3, 4};
        System.out.println(print_arr(arr));

        String ar[] = {"hello", "world"};
        System.out.println(print_arr(ar));

    }


    /* 泛型方法 泛型方法的 参数的数据类型 要是包装类*/
    public static<T> String print_arr(T array[]) {
        StringBuilder builder = new StringBuilder();
        builder.append("[");
        for (int i = 0; i < array.length; i++) {
            if (i == array.length - 1) {
                builder.append(array[i] + "]");
            } else {
                builder.append(array[i] + ", ");
            }
        }
        return builder.toString();
    }
}
